<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript" src="/pages/js/jquery.min.js"></script>
    <script type="text/javascript">
        //        使用ueditor编辑器
        $(function () {
            UE.getEditor('content', {initialFrameHeight: 500});
        });
    </script>
    <script type="text/javascript">
        $(function () {
            var newsId = localStorage['newsId'];

            detail(newsId);

            $("#News").click(function () {
                var url = "/admin/news/save";
                var id = $("#newsId").val(),
                        title = $("#title").val(),
                        introduction = $("#introduction").val(),
                        label = $("#label").val(),
                        author = $("#author").val(),
                        publishTime = $("#publishTime").val(),
//                    content = $("#content").val();
                        content = UE.getEditor('content').getContent();
                $.post(url, {
                    id: id,
                    title: title,
                    introduction: introduction,
                    label: label,
                    author: author,
                    publishTime: publishTime,
                    content: content
                }, function (result) {
                    if (result.status === 1) {
                        alert("保存成功！");
                        window.location.href="/pages/admin/admin_newslist.html";
                    }
                    else {
                        alert("保存失败！");
                        window.location.href = "/pages/admin/admin.html";
                    }
                })
            });
        })
        function detail(newsid) {
            var url = '/news/detail';
            $.post(url, {id: newsid}, function (result) {
                if (result.status === 1) {
                    var data = result.data;
                    $("#newsId").val(data.id);
                    $("#title").val(data.title);
                    $("#introduction").val(data.introduction);
                    $("#label").val(data.label);
                    $("#author").val(data.author);
                    $("#publishTime").val(data.publishTime);
//                    UE.getEditor('content').setContent(data.content);
                    window.setTimeout(function () {
                        setContent(data.content);
                    }, 1000);//一秒后再调用赋值方法

                }
                else {
                    window.location.href = "/pages/admin/admin_newslist.html";
                }
            })
        }
        //给富文本编辑框赋值
        function setContent(content) {
            UE.getEditor('content').execCommand('insertHtml', content);
        }
    </script>

    <title> 新闻编辑-查看详情</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/plugins/markdown/bootstrap-markdown.min.css"/>
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/calendar.css" rel="stylesheet">
</head>


<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>所有表单元素</h5>
                </div>
                <input id="newsId" type="text" hidden>
                <div class="ibox-content">
                    <div method="get" class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-10">
                                <input id="title" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">简介</label>
                            <div class="col-sm-10">
                                <input id="introduction" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">标签</label>
                            <div class="col-sm-10">
                                <input id="label" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">作者</label>
                            <div class="col-sm-10">
                                <input id="author" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group" id="pluscalender">
                            <label class="col-sm-2 control-label">发布时间</label>
                            <div class="col-sm-10">
                                <input id="publishTime" type="text" class="form-control"
                                       style="width:170px;padding:7px 10px;border:1px solid #ccc;margin-right:10px;">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">添加封面图</label>
                            <div class="col-sm-10">
                                <input id="file" type="file"/>推荐图片大小：5px * 5px
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="wrapper wrapper-content">
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="ibox float-e-margins">
                                        <div class="ibox-title">
                                            <h5>Markdown文本编辑器</h5>
                                            <div class="ibox-tools">
                                                <a class="collapse-link">
                                                    <i class="fa fa-chevron-up"></i>
                                                </a>
                                                <a class="dropdown-toggle" data-toggle="dropdown"
                                                   href="form_editors.html#">
                                                    <i class="fa fa-wrench"></i>
                                                </a>
                                                <ul class="dropdown-menu dropdown-user">
                                                    <li><a href="form_editors.html#">选项1</a>
                                                    </li>
                                                    <li><a href="form_editors.html#">选项2</a>
                                                    </li>
                                                </ul>
                                                <a class="close-link">
                                                    <i class="fa fa-times"></i>
                                                </a>
                                            </div>
                                        </div>
                                        <div>
                                            <script id="content" class="ibox-content" type="text/plain"
                                                    style="width:1024px;height:500px;">
                                            </script>
                                        </div>
                                        <!--<div class="ibox-content">-->
                                        <!--<textarea id="content" name="content" data-provide="markdown" rows="10"></textarea>-->
                                        <!--</div>-->
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button id="News" class="btn btn-primary" type="submit">保存内容</button>
                                    <button class="btn btn-white" type="submit">取消</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="js/content.js?v=1.0.0"></script>

    <!-- simditor -->
    <script type="text/javascript" src="js/plugins/markdown/markdown.js"></script>
    <script type="text/javascript" src="js/plugins/markdown/to-markdown.js"></script>
    <script type="text/javascript" src="js/plugins/markdown/bootstrap-markdown.js"></script>
    <script type="text/javascript" src="js/plugins/markdown/bootstrap-markdown.zh.js"></script>
    <script src="js/plugins/iCheck/icheck.min.js"></script>
    <script src="js/calendar.min.js"></script>

    <script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
    </script>

    <!-- 日期选择插件 -->
    <script>
        $(function () {
//            setTimeout(initCalendar,2000);
            initCalendar();

        });
        function initCalendar() {
            $("#publishTime").calendar({
                controlId: "divDate",                                 // 弹出的日期控件ID，默认: $(this).attr("id") + "Calendar"
                speed: 200,                                           // 三种预定速度之一的字符串("slow", "normal", or "fast")或表示动画时长的毫秒数值(如：1000),默认：200
                complement: true,                                     // 是否显示日期或年空白处的前后月的补充,默认：true
                readonly: true,                                       // 目标对象是否设为只读，默认：true
                upperLimit: new Date(),                               // 日期上限，默认：NaN(不限制)
                lowerLimit: new Date("2011/01/01"),                   // 日期下限，默认：NaN(不限制)
                // callback: function () {                               // 点击选择日期后的回调函数
                //     alert("您选择的日期是：" + $("#publishTime").val());
                // }
            });
        }
    </script>

</div>
</body>

</html>
